
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>知言</title>
    <meta name="title" content="">
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/index.css">
    <link rel="stylesheet" href="css/global.css">
    <link rel="stylesheet" href="css/font_24081_dddajmj0coc4n29.css">
    <link rel="stylesheet" href="layui/css/modules/layer/default/layer.css">
	<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <script src="js/jquery.min.js"></script>
	<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
	<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
</head>

<body>
    <div class="forum-header">
        <div class="layui-container">
            <a class="logo" href="index.html"><img src="img/logo.png" alt=""></a>

            <div class="fly-column-right layui-hide-xs" style="top:15px;">
                <span class="fly-search LAY_search" style="position:relative;top:8px" id="Search">
					<i class="layui-icon"></i>
				</span>
                <a href="edit.html" class="layui-btn">发表新帖</a>
            </div>


        </div>
    </div>

    <div class="layui-row layui-col-space15" style="margin-top:20px">
        <div class="layui-container">
            <div class="layui-row">
                <div class="layui-col-md8" id="questions">
                    
                    <div class="fly-panel">
                        <div class="box">
                            <div class="inner">
                                <a href="/" class="tab_current" id="all">全部</a>
									<a v-on:click="getQuestionList()" class="tab_current">刷新</a>
                            </div>
                        </div>
                        <ul class="fly-list">
                            <li v-for="q in questions">
                                <a href="" class="fly-avatar">
                                    <img src="img/questioner.jpg" v-bind:alt="q.username" />
                                </a>
                                <h2>
                                    <a href="" class="layui-badge">{{q.username}}</a>
                                    <a v-bind:href="'context.html?qid=' + q.qid">
					 				{{q.title}}
					 				</a>
                                </h2>
								
                                <div class="fly-list-info">
                                    
                                    <span>{{q.timestamp}}</span>
                                    
                                    <span class="fly-list-nums" style="">
										<i class="iconfont icon-pinglun1" title="回答" style="position:relative;top:1px;"></i>{{q.count}}
									</span>

                                </div>
                                <div class="fly-list-badge"></div>
								<div >{{q.content}}</div>
                            </li>
							
							
                        </ul>

                    </div>
                </div>

                <div class="layui-col-md4" style="position:relative; left:10px;font-size:16px">
                    <div class="fly-panel info" id="userControl">

                        <img src="img/login.png" alt="${user.name}" v-show="isLogin"/>
                        <div class="fly-detail-user user" v-show="isLogin">
                            <a href="/user/info" class="fly-link">
                                <cite>{{username}}</cite>
                            </a>
                            
                        </div>
                        <span class="fly-function" style="font-size:15px" v-show="isLogin">
							<a href="/user/setting">
								<i class="layui-icon layui-icon-set" title="设置"></i>
								设置
							</a>
							<a href="/user/message">
								<i class="layui-icon layui-icon-notice" title="消息"></i>
									消息 <span class="layui-badge" style="position:relative;bottom:1px;">99+</span>
							</a>
							<a v-on:click="logout">
								<i class="layui-icon layui-icon-note" title="注销" ></i>
								注销
							</a>
                         </span>

                        <h3 class="fly-panel-title">
                            <center>知言</center>
                        </h3>
                        <h5 class="fly-panel-title">
                            <center>一个关于分享和探索的地方</center>
                        </h5>
                        <div class="layui-row fly-panel-main" style="padding: 15px;" v-if="!isLogin">
                            <center>
                                <button class="layui-btn layui-btn-primary signin subLogin" v-on:click="login">现在登陆</button>
                            </center>
                        </div>
                        <br/>
                    </div>
                    <div class="fly-panel fly-rank fly-rank-reply" id="LAY_replyRank">
                        <h3 class="fly-panel-title">最近登录</h3>
                        <dl>
                            <dd>
                                <a href="/u/${m.id}"><img src="img/s.jpg" /><cite>admin</cite></a>
                            </dd>
							 <dd>
								<a href="/u/${m.id}"><img src="img/s.jpg" /><cite>故人帝梦</cite></a>
                            </dd>
                        </dl>
                    </div>
                        
                </div>
            </div>
        </div>
    </div>
    </div>



    <div class="fly-footer">

        <p>
            <a href="#" target="_blank">关于我们</a>
            <a href="#" target="_blank">友情链接</a>
            <a href="#" target="_blank">社区小黑板</a>

    </div>
    <script src="layui/layui.js"></script>
    <script src="layui/lay/modules/table.js"></script>
    <script src="layui/lay/modules/form.js"></script>
    <script src="layui/lay/modules/layer.js"></script>
    <script src="js/index.js"></script>
    
</body>
<script>
new Vue({
	el: '#userControl',
	data: {
	isLogin:false,
	username:""
	},
	
	mounted: function () {
		var storage=window.localStorage;
		//storage.setItem("uid",5)
		//storage.removeItem("uid")
		if(storage.uid){
			//console.log(storage.uid);
			this.isLogin=true;
			this.getName(Number(storage.uid));
		}else{
			this.isLogin=false;
		}
		//console.log(storage.uid);

	},
	methods: {
    logout: function () {
		var storage=window.localStorage;
		storage.removeItem("uid");
		this.isLogin=false;
		//console.log(storage.uid);
    },
	login: function () {
		self.location='login.html';
	/*
		var storage=window.localStorage;
		storage.setItem("uid",5)
		this.isLogin=true;
		console.log(storage.uid);*/
	},
	getName: function(uid){
		axios
		  .get('http://localhost:8080/api/query',{
			params:{
				uid:uid
			}
		  })
		  .then((response) => {
			  //console.log(response.data.data.username);
			  this.username=response.data.data.username;
			})
		  .catch(function (error) { // 请求失败处理
			//console.log(error);
			alert(error);
		});
	}
  }
})
new Vue({
  el: '#questions',
  data:function(){
	return {
	questions: null
  }},
  methods:{
	getQuestionList:function() {
		axios
		  .get('http://localhost:8080/api/question/list')
		  .then((response) => {
			  //console.log(response);
			  this.questions=response.data.data;
			})
		  .catch(function (error) { // 请求失败处理
			//console.log(error);
			alert(error);
		});
	  
	  }
  },
  mounted () {
	axios
      .get('http://localhost:8080/api/question/list')
      .then((response) => {
		  //console.log(response);
		  this.questions=response.data.data;
		})
      .catch(function (error) { // 请求失败处理
        //console.log(error);
		alert(error);
    });
  
  }
})
</script>
</html>